<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<style type="text/css">
        #div1{
        	width:100px;height: 100px;background: red;position:absolute;top:50px;left:600px;
        	/*left:0;*/
        }
        #div2{
        	width:1px;height: 300px;background: black;position: absolute;left:300px;top:0;
        }
	</style>
	<script type="text/javascript">
        function startMove(){
        	oDiv = document.getElementById('div1');
        	setInterval(function(){
                var speed = (300-oDiv.offsetLeft)/10; //速度 = （目标值-当前值）/ 缩放系数

                //判断运动状态，取整  Math.ceil():向上取整   Math.floor():向下取整
                speed = speed>0?Math.ceil(speed):Math.floor(speed);
                //document.title = oDiv.offsetLeft;
                oDiv.style.left = oDiv.offsetLeft+speed+'px';
        	},30);
        }
	</script>
</head>
<body>
   
    <input type="button" value="开始运动" onclick="startMove()" />
	<div id="div1"></div>
	<div id="div2"></div>
</body>
</html>